<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="java.net.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.io.File" %>

<HTML>
    <HEAD>
<%@ include file="/systeminfo/init_wev8.jsp" %>


<link href="./static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="./static/js/jquery/jquery-1.12.4.js" type="text/javascript"></script>
<script>
var jQuery12 = jQuery.noConflict(true);
</script>
<script src="./static/bootstrap/js/bootstrap_12.js" type="text/javascript"></script>
<script src="./static/js/others/bootbox.min.js" type="text/javascript"></script>
<script src="./static/js/util.js" type="text/javascript"></script>
<SCRIPT language="javascript" src="/js/weaver_wev8.js"></script>
    <meta name="description" content="monitor client">
    <meta name="author" content="admin">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Pragma" content="no-cache">
    <title>e-cology流程检测</title>
    <link href="./static/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="./static/custom/css/main.css" rel="stylesheet">
    <script src="./static/bootstrap-table/bootstrap-table_12.js" type="text/javascript"></script>
        <style>
#mainExecute {
    margin-top: 50px;
    margin-left: 100px;
    width: 900px;
    height: auto;
}
.fixed-table-body{
    height: auto;
    overflow:hidden;
}
#leftArea {
    clear:both;
    float: left;
    padding: 15px;
    width: 1020px;
    border: #000 1px solid;
}

#buttonArea {
    float: left;
    margin-left: 10px;
    padding: 15px;
    width: 300px;
}

#resultTitle {
    margin-left: 100px;
    clear: both;
    width: 800px;
    padding: 15px;
    line-height: 25px;
    font-size: 15px;
}
#resultArea {
    margin-left: 100px;
    clear: both;
    width: 800px;
    padding: 15px;
    line-height: 25px;
    font-size: 15px;
    border: #000 1px solid;
}

.showDiv {
    min-height: 30px;
    width: 1000px;
    margin-top:10px;
    line-height: 30px;
    font-size: 15px;
    padding-left: 10px;
    cursor: pointer;
    background-color: #f1f1f1;
    /*
    border-left: 0px;
    border-top: 0px;
    border-right: #ccc 3px solid !important;
    border-bottom: #eee 3px solid !important;
    */
}

.selectedDiv {
    /*
    border-left: #ccc 3px solid !important;
    border-top: #eee 3px solid !important;
    border-right: 0px !important;
    border-bottom: 0px !important;
    */
    background-color: #00aaaa !important;
}

.showDiv span {
    width: 100%;
    height: 100%;
}
.errorMsg{
    margin-top:10px;
    color:red;
    font-weight:bold;
    border:#000055 1px solid;
    margin-left:20px;
}
.needcheckMsg{
    margin-top:10px;
    color:blue;
    font-weight:bold;
    border:#000055 1px solid;
    margin-left:20px;
}
.okMsg{
    margin-top:10px;
    color:green;
    font-weight:bold;
    border:#000055 1px solid;
}
.fixsuccess{
    color:green;
}
.checkOK{
    background-image : url("./static/images/ok.png");
    background-repeat:no-repeat;
    background-position:center left;
}
.fixdataBtn{
    float:right;
    line-height:22px;
}
.spanimage{
    margin-left:20px;
}
.fixmessage{
    margin-left:10px;
}
</style>
    </head>
    <body>
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header" style="border-right:1px solid #dcdcdc;">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
           <span><img class="logo-less" src="./static/custom/images/logo.png"/></span>
          <a class="navbar-brand" href="#" style="color:#0f99f0;font-size:20px;">e-cology流程检测平台</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li style="margin-left:30px;"><a href="/flowtoolbar/checkMain.jsp" title="全局体检">全局体检</a></li>
            <li style="margin-left:30px;"><a href="/flowtoolbar/checkWithCondit.jsp" title="根据条件进行检测">局部数据检测</a></li>
            <li style="margin-left:30px;" class="active"><a href="/flowtoolbar/checkTools.jsp" title="常用工具">常用工具</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
    <div class="container container-template">
      
      <div class="jumbotron body">
        <!-- 
        <h2>体检规则</h2>
         -->
        <div class="row header">
            <div class="col-md-9">
                <p id="leadTipInfo" class="lead">请检测以下内容</p>
            </div>
            <div class="col-md-3">
            </div>
        </div>
         <div id="examineProgress" class="progress invisible">
          <div id="examineProgressBar" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">

          </div>
        </div>
      </div>
      <div id="errorRuleList"></div>
        <table id="ruleDataTable" data-classes="table table-hover table-condensed table-no-bordered" data-row-attributes="rowAttributes" data-row-style="rowStyle">
            <colgroup>
            <col width="0">
            <col width="5%">
            <col width="30%">
            <col width="10%">
            <col width="45%">
            <col width="10%">
           </colgroup>
        <thead>
          <tr>
            <th data-field="-" data-formatter="statusFormatter" data-align="center" data-valign="middle"></th>
            <th data-field="no" data-formatter="indexFormatter" data-align="center" data-valign="middle">序号</th>
            <th data-field="ruleName" data-align="center" data-valign="middle">名称</th>
            <th data-field="examineType" data-formatter="examineTypeFormatter" data-align="center" data-valign="middle">类型</th>
            <th data-field="classDesc" data-align="center" data-valign="middle">描述</th>
            <th data-field="linkjspurl" data-formatter="examineTypeFormatter" data-align="center" data-valign="middle">操作</th>
          </tr>
        </thead>
      </table>
    </div>
    
      <div class="container">
         <div id="example" class="modal fade in" style="display:none;height:408px;">
             <div class="modal-header">
                 <a class="close" data-dismiss="modal">×</a>
                 <h3>请输入条件</h3>
             </div>
             <input id="checkinput" type='hidden' value=''>
             <div>
                <input type= hidden id=exampleclassname value = ''>
             </div>
             <div class="modal-footer">
                 <a href="#" onclick='checkData(this);' class="btn btn-success">执行检测</a>
                 <a href="#" class="btn" data-dismiss="modal">关闭</a>
             </div>
         </div>
     </div>
<script>
<%
//设置检测列表
String resultStr = "";
//获取绝对路径
String absPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent();
ClassLoader classLoader = new URLClassLoader(new URL[]{new File(absPath + "/classes").toURI().toURL()},Thread.currentThread().getContextClassLoader());  
Class clazz=classLoader.loadClass("checkmain.CheckExucute");//使用loadClass方法加载class,这个class是在urls参数指定的classpath下边。  

Object checkInstance = clazz.newInstance();

Method taskMethod = clazz.getMethod("getAllCheckClass",String.class,String.class);//反射
resultStr = (String)taskMethod.invoke(checkInstance,absPath,"checktools");  

%>
var array = <%=resultStr%>;
var showlocation = 1;
//检测或者修复数据（全部）
function checkData(){
    var classnames= '';
    var infoNames= '';
    //获取选中的检测类型
    classnames = jQuery("#exampleclassname").val();
        
        //diag_saveaswf.close();
    var paramtotal = "";
    /*
    var paramStr = "";
    //拼接输入框
    jQuery("#checkinputdiv").find(".e8_outScroll input[type='hidden']").each(function(index1,ele1){
        if(paramStr.length > 0) paramStr += "##";
        paramStr += ele1.name + "=" + ele1.value;
    });
    */
    var paramStr = jQuery("#checkinput").val();
    if(window.console)console.log("paramStr",paramStr);
    if(paramtotal.length > 0) paramtotal += ";;";
    paramtotal += paramStr;
    paramtotal = "&paramMap=" + paramtotal;
    if(classnames == ''){
        window.top.alert("请选择有效的处理内容");
        return;
    }
    if(classnames.indexOf(",") == 0){
        classnames = classnames.substring(1);
    }
    if(infoNames.indexOf(",") == 0){
        infoNames = infoNames.substring(1);
    }
    jQuery.ajax({
        url : "/flowtoolbar/checkMainAjax.jsp",
        type : "post",
        processData : false,
        data : "classnames="+classnames+"&type="+0+paramtotal,
        dataType : "json",
        complete: function(){
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) {
        } , 
        success : function (data, textStatus) {
            //showResult(data);
                    var rule = data[0];
                    console.log("rule",rule);
                    if(!rule.classId){
                        rule.classId = rule.classname.substring(16);
                    }
                    var tr = jQuery12(document.getElementById("tr_"+rule.classId));
                    var td = tr.children(":last").eq(0);
                    
                    var _rule = rule;
                    if(window.console) console.log("_rule",_rule);
                    //console.log(_rule);
                    //插入一行，显示详情和修复按钮
                    var newtr = jQuery12(document.getElementById("newtr_"+_rule.classId));
                    if(newtr.length>0){
                        newtr.remove();
                    }
                    newtr = jQuery12("<tr></tr>")
                    newtr.attr("id","newtr_"+_rule.classId).css("background-color","#fff5f5").css("line-height","24px");
                    newtr.addClass("tr-tipinfo");
                    var newtd = jQuery12("<td></td>");
                    newtd.attr("colspan",5);
                    
                    newtd.css("text-align","left");
                    newtd.html(_rule.repairDesc);
                    newtr.append("<td/>").append(newtd);
                    var newtdop = jQuery12("<td></td>");
                    newtdop.css("text-align","center");
                    var resultList = _rule.retList;
                    if(window.console)console.log("_rule",_rule);
                    if(resultList){
                        var DetailHtml = "<table id='detailTable_" + _rule.classId + "' data-ajax='queryEvents'";
                        //DetailHtml += "     data-show-columns='true' data-show-refresh='true' data-show-toggle='true' data-show-export='true' ";
                        if(resultList.length > 10)DetailHtml += "    data-pagination='true' ";
                        DetailHtml += "    data-row-attributes='rowFormatter' data-locale='zh-CN'>";
                        DetailHtml += "    <thead>";
                        DetailHtml += "        <tr>";
                        DetailHtml += "              <th data-field='-' data-formatter='statusFormatter' data-align='center' data-valign='middle'></th>";
                        //DetailHtml += "            <th data-field='no' data-formatter='indexFormatter' data-align='center'>No.</th>";
                        DetailHtml += "            <th data-field='showMessage' data-align='center'>描述</th>";
                        DetailHtml += "            <th data-field='buttonname' style='width:90px' data-align='left' data-halign='center'>操作</th>";
                        DetailHtml += "        </tr>";
                        DetailHtml += "    </thead>";
                        DetailHtml += "    <tbody id='detailTable_" + _rule.classId + "Body' class='nowarp-table'>";
                        DetailHtml += "    </tbody>";
                        DetailHtml += "</table>";
                        
                    }
                    newtr.append(newtdop);
                    jQuery12(tr).after(newtr);
                    newtd.append(DetailHtml);
                    jQuery12("#detailTable_" + _rule.classId).bootstrapTable({
                        onRefresh: function () {
                            resultList.editHtml();
                            jQuery12("#detailTable_" + _rule.classId).bootstrapTable('load', resultList);
                        },
                        onPostBody : function(data){
                                jQuery12("#detailTable_" + _rule.classId).bootstrapTable('hideLoading');
                            }
                    }).bootstrapTable('refresh');
                    lastTr = tr;
        } 
    });
}
//修复数据（单选）
function fixData(obj){
    //获取选中的检测类型
    var classnames = jQuery(obj).parent().parent().find("input[name='classname']").val();
    if(classnames == ''){
        window.top.alert("没有classnames");
        return;
    }
    if(classnames.indexOf(",") == 0){
        classnames = classnames.substring(1);
    }
    var paramtotal = "";
    //遍历该按钮同级的隐藏变量
    var nameList = new Array();
    jQuery(obj).parent().parent().find(".param").each(function(index,ele){
        var tempname = jQuery(ele).attr("name");
        if(nameList.indexOf(tempname) < 0 ){
            nameList.push(tempname);
        }
    });
    //拼接字符串：变量之间使用##分割，不同map之间使用;;分割
    if(jQuery(obj).parent().parent().find(".resultList").length > 0){
        paramtotal +="##";
        paramtotal += "divid=" + jQuery(obj).parent().parent().find(".resultList").attr("id");
    }
    for(var i = 0; i < nameList.length; i++){
        if(paramtotal.length > 0){
            paramtotal +="##";
        }
        var tempname = nameList[i];
        var tempvalues="";
        jQuery(obj).parent().parent().find(".param[name='" + tempname + "']").each(function(index,ele){
            if(tempvalues.length > 0) tempvalues +=",";
            tempvalues += jQuery(ele).val();
        });
        paramtotal +=tempname + "=" + tempvalues;
    }
    if(paramtotal.length > 0){
        paramtotal = "&paramMap=" + paramtotal;
    }
    var trObject = jQuery(obj).parent().parent();
    jQuery.ajax({
        url : "/flowtoolbar/checkMainAjax.jsp",
        type : "post",
        processData : false,
        data : "classnames="+classnames+"&type=2" + paramtotal,
        dataType : "json",
        beforeSend : function(){
            showDivLoading(trObject);
        },
        complete: function(){
            hideDivLoading(trObject);
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) {
        } , 
        success : function (data, textStatus) {
            editshowfield(data,obj);
        } 
    });
}
function toogleSelect(obj){
    jQuery(obj).toggleClass("selectedDiv");
}
function chekcAll(obj){
    
    jQuery(obj).parent().find(".fixdataCheck").each(function(index,ele){
        if(this.disabled) return;
        ele.checked = obj.checked;
    });
    

}
//根据修复结果编辑检测内容
function editshowfield(data,obj){
    for(var i = 0; i < data.length;i++){
        var objectAll = data[i];
        if(objectAll.classname && objectAll.needReload == "1"){
            var resultList = objectAll.retList;
            resultList.editHtml();
            jQuery12("#detailTable_" + objectAll.classname.substring(12)).bootstrapTable('load', resultList);
            continue;
        }
        if(objectAll.retList){
            for(var j = 0; j < objectAll.retList.length;j++){
                var object = objectAll.retList[j];
                //修复成功
                if(object.result == 0){
                    if(object.divid != null && object.divid.length > 0){
                        jQuery("#" + object.divid).parent().parent().find(".fixdataBtn").attr("disabled","disabled");
                        var message = "修复成功";
                        if(object.fixMessage){
                            message = object.fixMessage;
                        }
                        if(jQuery("#" + object.divid).find(".fixmessage").length > 0 ){
                            if(!jQuery("#" + object.divid).find(".fixmessage").hasClass("fixsuccess")){
                              jQuery("#" + object.divid).find(".fixmessage").addClass("fixsuccess");
                            }
                            jQuery("#" + object.divid).find(".fixmessage").html(message);
                        }else{
                            jQuery("#" + object.divid).append("<span class='fixmessage fixsuccess'>" + message + "</span>");
                        }
                        jQuery(obj).parent().html("-");
                    }
                }else{
                    if(object.divid != null && object.divid.length > 0){
                        var message = "修复失败";
                        if(object.showMessage){
                            message = object.showMessage;
                        }
                        if(jQuery("#" + object.divid).find(".fixmessage").length > 0 ){
                            jQuery("#" + object.divid).find(".fixmessage").html(message);
                        }else{
                            jQuery("#" + object.divid).append("<span class='fixmessage'>" + message + "</span>");
                        }
                    }
                }
            }
        }
    }
}
//显示检测内容
var cnt = 0;

var examineRules = <%=resultStr%>;
var orderExamineRules = [];
var inExamine = false;
function rowStyle(row, index) {
    return {
      classes: 'tr-tipinfo'
    };
}

function rowAttributes(row, index) {
    return {
      'title': row.ruleDesc,
      'id': 'tr_'+row.classId
    };
}

function statusFormatter(value, row, index) {
    var cell = ['<div class="form-group"><div class="text-center">',
                '<span class="glyphicon glyphicon-refresh glyphicon-refresh-animate status status-loading hidden"></span>',
                '<span class="glyphicon status status-ok hidden"></span>',
                '<span class="glyphicon status status-warning hidden"></span>',
                '</div></div>'];
    return cell.join('');
}

function indexFormatter(value, row, index) {
    return index + 1;
}

function examineTypeFormatter(value, row, index) {
    return value;
}

function operationFormatter(value, row, index) {
    return value;
}
    var diag_saveaswf
function showModalByid(jsppath,classname){
    jQuery("#exampleclassname").val(classname);
    diag_saveaswf = new window.top.Dialog('moveToTop' );
    diag_saveaswf.currentWindow = window;
    diag_saveaswf.Width = 750;
    diag_saveaswf.Height = 450;
    diag_saveaswf.Modal = true;
    diag_saveaswf.Title = "请输入条件"; 
    diag_saveaswf.URL = jsppath;
    diag_saveaswf.OKEvent = function(){
                    var paramStr = "";
                    //拼接输入框
                    jQuery(document.getElementById('_DialogFrame_moveToTop').contentWindow.document.body).find("#inputDiv").find(".e8_outScroll input[type='hidden']").each(function(index1,ele1){
                        if(paramStr.length > 0) paramStr += "##";
                        paramStr += ele1.name + "=" + ele1.value;
                    });
                    //拼接输入框
                    jQuery(document.getElementById('_DialogFrame_moveToTop').contentWindow.document.body).find(".paraminput").each(function(index1,ele1){
                        if(paramStr.length > 0) paramStr += "##";
                        paramStr += ele1.name + "=" + ele1.value;
                    });
                    jQuery("#checkinput").val(paramStr);
                    checkData();
                    diag_saveaswf.close();
                    };//点击确定后调用的方法
    diag_saveaswf.show();
    
    //jQuery("#exampleIframe")[0].src=jsppath;
    //jQuery("#exampleclassname").val(classname);
    //jQuery("#example").modal();
}
function startCheck(){
    //alert(paramStr);
    jQuery("#checkinput").val("");
    //jQuery("#checkinput").val(paramStr);

}
function showExamineProgress(percentage){
    //jQuery12('#examineProgressBar').attr({'aria-valuenow':percentage}).css({'width':percentage+'%'}).html(percentage+'%');
    jQuery12('#examineProgress').removeClass('invisible');
}

function hideExamineProgress(){
    jQuery12('#examineProgress').addClass('invisible');
    jQuery12('#examineProgressBar').attr({'aria-valuenow':0}).css({'width':'0%'}).html('0%');
}

function showRuleLoading(classId){
    jQuery12('#tr_'+classId).attr('class', 'tr-tipinfo info');
    jQuery12('#tr_'+classId + ' .status').addClass('hidden');
    jQuery12('#tr_'+classId + ' .status.status-loading').removeClass('hidden');
}
function hideDivProgress(Obj){
    jQuery12('#examineProgress').addClass('invisible');
    jQuery12('#examineProgressBar').attr({'aria-valuenow':0}).css({'width':'0%'}).html('0%');
}

function showDivLoading(Obj){
    Obj.attr('class', 'tr-tipinfo info');
    Obj.find('.status').addClass('hidden');
    Obj.find('.status.status-loading').removeClass('hidden');
}
function hideDivLoading(Obj){
    Obj.attr('class', 'tr-tipinfo info');
    Obj.find('.status').addClass('hidden');
    Obj.find('.status.status-ok').removeClass('hidden');
}

function showRuleOK(classId){
    jQuery12('#tr_'+classId).attr('class', 'tr-tipinfo success');
    jQuery12('#tr_'+classId + ' .status').addClass('hidden');
    jQuery12('#tr_'+classId + ' .status.status-ok').removeClass('hidden');
}

function showRuleWaring(classId, repairDesc){
    jQuery12('#tr_'+classId).attr('class', 'tr-tipinfo danger');
    jQuery12('#tr_'+classId + ' .status').addClass('hidden');
    jQuery12('#tr_'+classId + ' .status.status-warning').removeClass('hidden');
    
    //TODO 删除并添加
    //if(repairDesc){
    //  jQuery12('#tr_'+classId + ' .repariDesc').addClass('hidden');
    //}
}

var count = 0;
var total = 1;
var errExamineResults = [];
var errExamineRules = [];

//排序
function orderExaminRulesFn(){
    orderExamineRules = errExamineRules.concat(examineRules);
    orderExamineRules = orderExamineRules.unique();
    jQuery12('#ruleDataTable').bootstrapTable('load', orderExamineRules);
    
}

Array.prototype.unique = function(){
 var res = [];
 var json = {};
 for(var i = 0; i < this.length; i++){
  if(!json[this[i].classId]){
   res.push(this[i]);
   json[this[i].classId] = 1;
  }
 }
 return res;
}

var errRepairResults = [];
var errRepairSuccessResults = [];
var isRepairedFlag = false;



function rowFormatter(row, index){
    return {title: row.eventMsg};
}



jQuery12(function(){
    jQuery12('#ruleDataTable').bootstrapTable({
        onRefresh: function () {
            jQuery12('#ruleDataTable').bootstrapTable('load', examineRules);
        }
    }).bootstrapTable('refresh');
    
    
    
});
Array.prototype.clone=function(){ return [].concat(this); }
Array.prototype.editHtml = function(){
 for(var i = 0; i < this.length; i++){
     
    var resultObj = this[i];
    var DetailHtml = "<div class='resultList'";
    if(resultObj.classname){
        DetailHtml +=" id='" + resultObj.classname.substring(12) + "_" + i + "' ";
    }
    DetailHtml +="><span class='checkmessage'>" + resultObj.showMessage;
    //遍历Object
    for(var key in resultObj) {
        //过滤公用属性： 显示信息 按钮名称 输入框列表 链接地址 连接显示名称
        if(key == "showMessage" || key == "buttonname" || key == "inputnamelist" || key == "linkurl" || key == "linkname" || key == "fixMessage"){
            continue;
        }
        DetailHtml+= "<input type='hidden' class='param' name = '" + key + "' value='" + resultObj[key] + "'>";
    }
    if(resultObj.inputnamelist){
        var inputArray = resultObj.inputnamelist.split(",");
        for(var k =0;k< inputArray.length;k++ ){
            var inputname = inputArray[k];
            DetailHtml+= "<input type='text' class='param showinput' name = '" + inputname + "' value=''>";
        }
    }
    if(resultObj.linkurl && resultObj.linkname){
        DetailHtml+= "<a href=" + resultObj.linkurl +" target='_new" + cnt + "'>" + resultObj.linkname + "</a>";
    }
    DetailHtml+= "</div></span>";
    this[i].showMessage = DetailHtml;
    
    if(resultObj.buttonname){
        var buttonHtml= "<a href='#' onclick='fixData(this)'>" + resultObj.buttonname + "</a>";
        this[i].buttonname = buttonHtml;
    }
 }
 return this;
}
--></script>